
package uestc.bitman.edxapp;

import uestc.bitman.edxapp.downloading.DownloadingTaskAdapter;
import uestc.bitman.edxapp.tools.VideoDownloadTools;

import android.app.Application;
import android.content.Context;

/**
 * @author hackeris
 * @category Some global objects of this app
 */
public class EdxApp extends Application {

    private static Context sContext;

    private static EdxStudentUser studentUser;

    private static DownloadingTaskAdapter downloadingTaskAdapter;

    @Override
    public void onCreate() {
        super.onCreate();
        sContext = getApplicationContext();
    }

    public static Context getAppContext() {
        return EdxApp.sContext;
    }

    public static void createEdxStudentUser(String userEmail, String userPass) {
        studentUser = new EdxStudentUser(userEmail, userPass);
    }

    public static EdxStudentUser getEdxAppUser() {
        return studentUser;
    }

    public static void setDownloadingTaskAdapter(DownloadingTaskAdapter taskAdapter) {
        downloadingTaskAdapter = taskAdapter;
    }

    public static DownloadingTaskAdapter getDownloadingTaskAdapter() {
        return downloadingTaskAdapter;
    }

    public static void startDownloadTask(String url, String sectionName, String chapterName,
            String courseName, String videoTitle) {
        String fileName = VideoDownloadTools.generateHashFileName(courseName, chapterName,
                sectionName, videoTitle) + url.substring(url.lastIndexOf("."), url.length());
        downloadingTaskAdapter.append(url, fileName, sectionName, chapterName, courseName,
                videoTitle);
    }
}
